<?php
/**
 * Abstract class that is used as base for other classes.
 *
 * @link http://haml-lang.com/ Original Haml parser (for Ruby)
 * @license http://www.opensource.org/licenses/mit-license.php MIT (X11) License
 * @author Rik Bruil <info@rikbruil.com>
 * @package Hamlap
 */
abstract class Hamlap_Base
{
	/**
	 * Key-value paired array with options for this object
	 * @var array
	 */
	private $options = array();

	/**
	 * Set the options from the key-value paired array
	 * @param array $options
	 * @return Hamlap_Base
	 */
	public function setOptions(array $options = array())
	{
		if(count($options))
			foreach($options as $k => $v)
				$this->setOption($k, $v);

		return $this;
	}

	/**
	 * Set an option by the given name with the given value
	 * @param string $name
	 * @param mixed $value
	 * @return Hamlap_Base
	 */
	public function setOption($name, $value)
	{
		$name = strtolower(trim($name));
		$this->options[$name] = (is_string($value)) ? trim($value) : $value;
		return $this;
	}

	/**
	 * Get the options for this object
	 * @return array
	 */
	public function getOptions()
	{
		return $this->options;
	}

	/**
	 * Get the option with the specified name
	 * or null if the options doesn't exist
	 * @param string $name
	 * @return mixed|null
	 */
	public function getOption($name)
	{
		$name = strtolower(trim($name));
		return (isset($this->options[$name])) ? $this->options[$name] : null;
	}

	/**
	 * Return the output for this object by calling the render() method
	 * @return string
	 */
	public function __toString()
	{
		return $this->render();
	}

	/**
	 * Render the output for this object
	 * @return string
	 */
	abstract public function render();
}